package com.itheima.controller;

import com.itheima.goods.pojo.Category;
import com.itheima.service.CategoryService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping
    public Result finAll() {
        return categoryService.findAll();
    }

    @PostMapping
    public Result add(@RequestBody Category category) {
        return categoryService.add(category);
    }

    @GetMapping("/search/{page}/{size}")
    public Result findPage(
            @PathVariable("page") Integer page, @PathVariable("size") Integer size
    ) {
        return categoryService.findPage(page, size);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        return categoryService.findById(id);
    }
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Integer id,@RequestBody Category category){
        return categoryService.updateById(id,category);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return categoryService.deleteById(id);
    }
    @PostMapping("/search/{page}/{size}")
    public Result findPage(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size,
            @RequestBody Category category){
        return categoryService.findPage(page,size,category);
    }
}
